import React from 'react'
import { Layout} from 'antd';
import Table from '../Table'
import Editor from "../Editor"
import {useSelector,useDispatch,connect} from 'react-redux'
import "./tr.css"

const {Content} = Layout;



const User = () => {

    const userList = useSelector(state=> state.user.userList)
    const valueList = useSelector(state=> state.value.valueList)
    const dispatch = useDispatch()
  let value;
  
  const columns = [
    {
      title: '用户头像',
      key: 'UserImg',
      dataIndex: 'UserImg',
      valueType: 'avatar',
      hideInSearch:true
  },
    {
        title: '用户名',
        dataIndex: 'Username',
        key: 'Username',
        ellipsis:true
    },
    {
        title: '用户微信号',
        key: 'Userwxno',
        dataIndex: 'Userwxno',
        valueType: 'text',
    },
    {
        title: '用户电话号码',
        key: 'Usertno',
        dataIndex: 'Usertno',
        valueType: 'text',
    },
    

    {
        title: '操作',
        key: 'option',
        width: 120,
        valueType: 'option',
        render: (text,record,index,action) => [<div onClick={()=>{
          dispatch({type:'get',con:record});
        }}><Editor ques={user} url="http://49.233.107.127:2002"/></div>
        , <a onClick={async ()=>{

          await fetch(`http://49.233.107.127:2002/${record.Userwxno}`,{
          method:'delete',
          headers: {
            'Content-Type': 'application/json;charset=UTF-8'
          },
          body:JSON.stringify(record)
        })
        dispatch({type:'delete',content:['delete']})
        }}>删除</a>]
      }];
const right = {
  }

  const user = [
    {name:'Username',label:'用户名',tooltip:'最长为24位',placeholder:'请输入用户名称'},
    {name:'UserImg',label:'用户头像',placeholder:'上传头像'},
    {name:'Userwxno',label:'用户微信号',tooltip:'最长为24位',placeholder:'请输入微信号码'},
    {name:'Usertno',label:'用户手机号',tooltip:'最长为24位',placeholder:'请输入手机号码'},
    {name:'Message',label:'信息',tooltip:'最长为24位',placeholder:'请输入message'},
    {name:'Collimg',label:'收藏图片',tooltip:'最长为24位',placeholder:'请输入收藏图片'},
    {name:'Collcontent',label:'收藏内容',tooltip:'最长为24位',placeholder:'请输入收藏内容'},
    {name:'Publishimg',label:'发布的照片',tooltip:'最长为24位',placeholder:'请输入发布的照片'},
    {name:'Publishcontent',label:'发布内容',tooltip:'最长为24位',placeholder:'请输入发布的内容'},
    {name:'Likeimg',label:'喜欢的照片',tooltip:'最长为24位',placeholder:'请输入喜欢的照片'},
    {name:'Likecontent',label:'喜欢的内容',tooltip:'最长为24位',placeholder:'请输入喜欢的内容'}
]

    return (
        <Content className="site-layout-background" style={{paddingLeft: 10,margin: 0,minHeight: 280,}}>
          <Table title="用户管理" columns={columns} right={right} url="http://49.233.107.127:2002" ques={user} />
        </Content>
    )
}

export default connect()(User)